package com.coda.service.impl;

import com.coda.entity.SystemPost;
import com.coda.mapper.SystemPostMapper;
import com.coda.result.PageResult;
import com.coda.result.Result;
import com.coda.service.SystemPostService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SystemPostServiceImpl implements SystemPostService {
    @Autowired
    private SystemPostMapper systemPostMapper;
    /**
     * 分页查询岗位信息
     * @param current
     * @param size
     */
    @Override
    public PageResult getPageList(Integer current, Integer size) {
        PageHelper.startPage(current,size);
        Page<SystemPost> page = systemPostMapper.PageList(current,size);
        PageResult pageResult = new PageResult(page.getTotal(),page.getResult());
        return pageResult;
    }

    /**
     * 保存或更新岗位信息
     * @param systemPost
     */
    @Override
    public void saveOrUpdate(SystemPost systemPost) {
        if (systemPost.getId() == null){
            systemPostMapper.insert(systemPost);
        }else {
            systemPostMapper.update(systemPost);
        }
    }

    /**
     * 根据id查询岗位信息
     * @param id
     */
    @Override
    public SystemPost getPostById(Long id) {
        SystemPost systemPost = systemPostMapper.getPostById(id);
        return systemPost;
    }

    /**
     * 根据id修改岗位状态
     * @param id
     * @param status
     */
    @Override
    public void updateStatus(Long id, Integer status) {
        SystemPost systemPost = new SystemPost();
        systemPost.setId(id);
        systemPost.setStatus(status);
        systemPostMapper.updateStatus(systemPost);
    }

    /**
     * 根据ID删除岗位信息
     * @param id
     */
    @Override
    public void deleteById(Long id) {
        systemPostMapper.deleteById(id);
    }

    /**
     * 获取全部岗位列表
     * @return
     */
    @Override
    public List<SystemPost> getList() {
        List<SystemPost> systemPost = systemPostMapper.getList();
        return systemPost;
    }
}
